import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Router, ActivatedRoute } from '@angular/router';
import { CarouselService } from '../../service/carousel.service';
import { Carousel } from '../../model/carousel';

@Component({
  selector: 'app-upload',
  templateUrl: './upload.component.html',
  styleUrls: ['./upload.component.css']
})
export class UploadComponent implements OnInit {

  selectedFile: string;
  cl:Array<Carousel>;
  parm:string;
  
  constructor(
    private http:HttpClient,
    private router:Router,
    private routerinfo:ActivatedRoute,
    private carouselservice:CarouselService) { 
      this.parm=this.routerinfo.snapshot.params["id"];
      this.cl=new Array();
    }

  ngOnInit() {
    this.loadCarouselList();
  }

  private loadCarouselList(){
    this.cl=new Array();
    this.carouselservice.getCarouselList().
    then((data:any)=>{
           this.cl=data;
   
    })
  }
  
  addCarousel(){
    this.router.navigate(['editCarousel','add']);
  }

  editCarousel(id:string){
    this.router.navigate(['editCarousel',id]);
  }

  deleteCarousel(id:string){
      this.carouselservice.deleteCarousel(id).
      then((flag:boolean)=>{
        if(flag==true){
          this.loadCarouselList();
        }
        else{
          alert("删除异常，请刷新后重试");
        }
      })
  }
  
  

}
